const App = {
  mixins: [Query],
  data() {
    return {
      // 添加当前选中的组织序列号
      currentOrgSerial: '',
      // 删除日期格式化方法引用
      page: {
        value1: '',
        PageNumber: 1, //页码
        RowAmount: 10,
        Condition: window.btoa(unescape(encodeURIComponent("%%,%%")))
      },
    };
  },
  mounted() {
    // this.Treedata();
  },
  methods: {

    // 修改编辑跳转
    handleEdit(row) {
      let { primary_key } = JSON.parse(document.getElementById("table").getAttribute("data-options"));
      window.location.href = `./add.html?action=Modify&nodeKey=${row[primary_key]}`;
    },

    // 修改添加跳转
    workteamAdd() {
      window.location.href = "./add.html?action=Add";
    },


    handleNews(row) {
      const activitySerial = row.Party_Organization_Activity_SerialNumber;
      window.location.href = `./index_new.html?Party_Organization_Activity_SerialNumber=${activitySerial}`;
    },

    handleIntroduce(row) {
      window.location.href = "./addIntroduce.html?action=Modify&nodeKey=" + row.Party_Organization_Activity_SerialNumber;
    },

    // 树节点点击事件
    handleNodeClick(data, node) {
      // 保存当前选中的组织序列号
      this.currentOrgSerial = data.Organization_SerialNumber;
      console.log(data.Organization_SerialNumber);

      console.log(window.btoa(unescape(encodeURIComponent("%" + this.page.value1 + "%,%" + data.Organization_SerialNumber + "%"))));

      // 构建查询条件：根据选中的组织序列号查询
      this.page.Condition = window.btoa(unescape(encodeURIComponent("%" + this.page.value1 + "%,%" + data.Organization_SerialNumber + "%")));

      this.postgetList(this.page);
    },

    // 查询方法 - 包含组织过滤条件
    check() {
      // 如果当前有选中的组织，包含在条件中
      // const orgCondition = this.currentOrgSerial ? `%${this.currentOrgSerial}%` : '%%';
      const orgCondition = '%%';
      this.page.Condition = window.btoa(
        unescape(encodeURIComponent(`%${this.page.value1}%,${orgCondition}`))
      );
      this.postgetList(this.page);
    },

    // 重置方法 - 清除组织选择
    reset() {
      this.page.value1 = '';
      this.currentOrgSerial = ''; // 清除选中的组织
      this.page.Condition = window.btoa(unescape(encodeURIComponent("%%")));
      this.postgetList(this.page);
    },

    // 获取树数据 - 确保返回的数据包含value字段
    // Treedata() {
    //   const _this = this;
    //   $.ajax({
    //     headers: requestHeaders(),
    //     url: `${mh}/generalBusiness/generalQueryByTableName`,
    //     type: "POST",
    //     data: {
    //       Data: 'north_organization',
    //       Condition: "Row_Status='0'"
    //     },
    //     success: function (data) {
    //       const treeData = [];
    //       const nodes = data || [];

    //       const parentNodes = nodes.filter(node => !node.Parent_SerialNumber);

    //       parentNodes.forEach(parent => {
    //         const treeNode = {
    //           ...parent,
    //           label: parent.Organization_name,
    //           value: parent.Organization_SerialNumber, // 确保value字段存在
    //           children: []
    //         };

    //         const childNodes = nodes.filter(node =>
    //           node.Parent_SerialNumber === parent.Organization_SerialNumber
    //         );

    //         childNodes.forEach(child => {
    //           treeNode.children.push({
    //             ...child,
    //             label: child.Organization_name,
    //             value: child.Organization_SerialNumber // 确保value字段存在
    //           });
    //         });

    //         treeData.push(treeNode);
    //       });

    //       _this.treeData = treeData;
    //     },
    //     complete: (XMLHttpRequest) => {
    //       requestPretreatment(XMLHttpRequest);
    //     },
    //     dataType: "json",
    //   });
    // },
  },
};

const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");